﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;

namespace DAL
{
    /// <summary>
    /// 副屏业务
    /// </summary>
    public class order_markDal
    {
        /// <summary>
        /// 添加副屏记录
        /// </summary>
        /// <param name="ordsn"></param>
        /// <param name="goods"></param>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static int Addrecord(string ordsn, string goods, string merchantid,string price)
        {
            string sql = "REPLACE into ms_order_mark(ordsn,merchnatid,goods,addtime,price) values(@ordsn,@merchnatid,@goods,@addtime,@price)";
            MySqlParameter[] values = new MySqlParameter[5];
            values[0] = new MySqlParameter("ordsn", ordsn);
            values[1] = new MySqlParameter("merchnatid", merchantid);
            values[2] = new MySqlParameter("goods", goods);
            values[3] = new MySqlParameter("addtime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            values[4] = new MySqlParameter("price", price);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="ordsn"></param>
        /// <returns></returns>
        public static int Delbyordsn(string ordsn)
        {
            string sql = "delete from ms_order_mark where ordsn=@ordsn";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("ordsn", ordsn);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 查副屏显示内容
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static ms_order_mark Querybymerchantid(string merchantid)
        {
            string sql = "select * from ms_order_mark where merchnatid=@merchnatid and status=0 order by addtime desc limit 1";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchnatid", merchantid);
            ms_order_mark mark = new ms_order_mark();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            if (rd.Read())
            {                
                mark.ordsn = rd["ordsn"].ToString();
                mark.merchnatid = rd["merchnatid"].ToString();
                mark.goods = rd["goods"].ToString();
                mark.price = rd["price"].ToString();
            }
            rd.Close();
            return mark;
        }
    }
}
